<template>
<view class="page__bd">
	<custom-navbar bgColor="bg-white shadow" :isBack="true" :isHome="true">
		<block slot="backText">返回</block>
		<block slot="content">我的订单</block>
	</custom-navbar>
	<view class="daui-navbar bg-white">
		<view class="daui-navbar__item" :class="index==TabCur?'current':''" v-for="(item,index) in nav" :key="index" @tap="tabSelect" :data-id="index">
			{{item}}
		</view>
	</view>
	<view class="ord-list">
		<view class="daui-card daui-card__full daui-card_access" v-for="(item,index) in orderList" :key="index">
			<view class="daui-card__hd">
				<text>订单号：{{item.order_no}}</text>  
				<text class="margin-left-sm" v-if="item.ord_type == 6" :style="{color:item.ord_type_color}">{{item.ord_type_show}}</text>
				<text class="pull-right" :class="item.trade_status_class">{{item.trade_status_show}}</text>
			</view>
			<view class="daui-card__bd" v-if="item.ord_type == 1">
				<block v-for="(item2,index2) in item['orderProduct']" :key="index2">
				<view class="daui-media daui-media_appmsg daui-media_product">
					<view class="daui-media__hd">
						<image class="daui-media__thumb" :src="item2.logo_show"></image>
					</view>
					<view class="daui-media__bd">
						<view class="daui-media__subbox margin-top-xs">
							<view class="daui-media__subbox_hd">
								<view class="daui-media__title">{{item2.prod_name}}</view>
							</view>
							<view class="daui-media__subbox_bd">
								<text class="text-price text-lg text-red">{{item2.one_price}}</text>
							</view>
						</view>
						<view class="daui-media__subbox margin-top-xs">
							<view class="daui-media__subbox_hd">
								<view class="daui-media__work">重量：{{item2.weight}}kg</view>
							</view>
							<view class="daui-media__subbox_bd">
								<view class="daui-media__work margin-top-xs" v-if="item2.full_give_open">
									购买{{item2.buy_num}}，赠送{{item2.give_num}}，实际{{item2.reality_num}}
									<text class="zzui-feedtag line-green ml10">满{{item2.full_num}}送{{item2.give_num}}</text>
								</view>
								<view class="daui-media__work margin-top-xs" v-else>
									数量*{{item2.reality_num}}
								</view>
							</view>
						</view>
						<view class="daui-media__work margin-top-xs" v-if="item2.is_spec_open==1">
							规格：<text>{{item2.spec_1}}</text>
							<text v-if="item2.spec_2">，{{item2.spec_2}}</text>
						</view>
						<view class="daui-media__desc">品牌：{{item2.brand_name}}<text class="margin-left-xs">产地：{{item2.originplace}}</text></view>
						<view class="daui-media__desc">包装方式：{{item2.package}}</view>
						<view class="daui-media__work margin-top-xs" v-if="item2.lite_content">
							<text class="zzui-feedtag line-red">{{item2.lite_content}}</text>
						</view>
					</view>
				</view>
				</block>
			</view>
			<view class="daui-card__ft" v-if="item.ord_type == 1 && 0">
				<view class="daui-cell daui-cell_access text-right">
					<view class="daui-cell__bd">
						<text>共<text class="text-red">{{item.realityNum}}</text>件商品，</text>
						<text>总金额：<text class="text-price text-red text-xl">{{item.total_fee}}</text></text>
						<text>(含运费<text>￥{{item.delivery_fee}}</text>)</text>
					</view>
				</view>
			</view>
			<view class="daui-card__bd" v-if="item.ord_type == 6 && item.ord_subtype == 1">
				<view class="daui-media daui-media_appmsg">
					<view class="daui-media__bd">
						<view>订餐人：{{item.realname}}</view>
						<view>手机号：{{item.mobile}}</view>
						<view>用餐人数：{{item.personnum}}</view>
						<view>用餐时间：{{item.persontime_cn}}</view>
					</view>
				</view>
			</view>
			<view class="daui-card__bd" v-if="item.ord_type == 6 && item.ord_subtype == 2">
				<view class="daui-picture" scroll-x="true">
					<block v-for="(item2,index2) in item['orderDishgood']" :key="index2">
					<view class="daui-picture-item">
						<image :src="item2.logo"></image>
					</view>
					</block>
				</view>
			</view>
			<view class="daui-card__ft" v-if="item.ord_type == 6">
				<view class="daui-cell daui-cell_access text-right">
					<view class="daui-cell__bd">
						<text>共<text class="text-red">{{item.realityNum}}</text>件商品，</text>
						<text>总金额：<text class="text-price text-red text-xl">{{item.total_fee}}</text></text>
					</view>
				</view>
			</view>
			<view class="daui-card__ft" v-if="0">
				<view class="daui-cell daui-cell_access text-right">
					<view class="daui-cell__bd">
						下单时间：{{item.create_time_show}}
					</view>
				</view>
			</view>
			<view class="daui-card__bd" v-if="item.ord_type == 21">
				<view class="daui-media daui-media_appmsg">
					<view class="daui-media__bd">
						<h1 class="wefix-media-box__we_title ord-pro-link"><a href="{:url('mobmall/card/index')}">会员卡类型：{$cardInfo['name']}</a></h1>
						<view class="wefix-media-box__we_work">会员卡价格：￥{$cardInfo['real_price']}元</view>
						<view class="wefix-media-box__we_second">有效期：{$cardInfo['expire_type_show']}</view>
						<view class="wefix-media-box__we_second">购买数量：1</view>
					</view>
				</view>
			</view>
			<view class="daui-card__bd" v-if="item.ord_type == 31">
				<view class="daui-media daui-media_appmsg">
					<view class="daui-media__bd">
						<view class="daui-media__title">{{balance_name}}充值</view>
						<view class="daui-media__second">
							充值{{item.recordInfo.amount}}元，赠送{{item.recordInfo.give}}元，实得{{item.recordInfo.realamount}}元
						</view>
					</view>
				</view>
			</view>
			<view class="daui-card__ft" v-if="item.ord_type == 41">
				<view class="daui-media daui-media_appmsg">
					<view class="daui-media__bd">
						<view class="daui-media__title">扫码付款</view>
						<view class="daui-media__second">
							<view>{{item.total_fee}}元</view>
							<view>备注：{{item.content}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="daui-card__ft">
				<view class="daui-cell">
					<view class="daui-cell__bd">
						<text>共<text class="text-red">{{item.realityNum}}</text>件商品，</text>
						<text>合计：<text class="text-price text-red">{{item.total_fee}}</text></text>
					</view>
					<view class="daui-cell__ft">
						<button class="daui-btn daui-btn_sm line-black circle margin-right-sm" v-if="item.trade_status == 1" @click="doCancel(item.id)">取消订单</button>
						<button class="daui-btn daui-btn_sm line-orange" v-if="item.show_pay_btn == 1" @click="openOrderDetail(item.id)">立即支付</button>
						<button class="daui-btn daui-btn_sm line-cyan" v-else @click="openOrderDetail(item.id)">查看详情</button>
						<button class="daui-btn daui-btn_sm line-mauve margin-left-xs" v-if="item.trade_status == 5 && item.evaluation_status == 1" @click="openEvaluationOperate(item.id)">我要评价</button>
					</view>
				</view>
			</view>
		</view>
	</view>
	<view class="daui-load" :class="!loadding?'loading':'over'" v-if="orderNum > 0"><view class="daui-load-in"><view class="daui-nomore-text"></view></view></view>
	<view class="daui-empty" v-if="loadding == true && orderNum == 0">
		<view class="daui-empty__icon">
			<image src="https://www.uucms.com/danceui_res/empty/order.png"></image>
		</view>
		<view class="daui-empty__bd">
			暂无订单
		</view>
		<view class="daui-btn bg-primary round" :hover-stay-time="150"  @tap="openProductList">去逛逛</view>
	</view>
	
	<!--toast提示-->
	<daui-toast ref="toast"></daui-toast>
</view>
</template>

<script>
import danceuiTool from '../../utils/danceuiTool';
import http from "../../server/api-mine.js";
export default {
	data() {
		return {
			balance_name: '',
			TabCur: 0,
			nav: ['全部', '待付款', '待发货', '待收货', '待评价'],
			list_param:{
				p:1
			},
			nowPage: 1,
			loadding: false,
			pullUpOn: true,
			orderNum: 0,
			orderList: [],
		}
	},
	onLoad(options) {
		console.log('onLoad的参数:', options);
		if (options.sort) {
			this.TabCur = options.sort
		}
		this.sort = options.sort ? options.sort : 0;
		console.log('this.sort:', this.sort);
		this.list_param = {sort: this.sort};
		this.balance_name = uni.getStorageSync('balance_name');
		this.getData();
	},
	// onShow() {
	// 	// let order_sort = uni.getStorageSync('order_sort');
	// 	// if(order_sort){
	// 	// 	console.log('order_sort:', order_sort);
	// 	// 	this.TabCur = order_sort;
	// 	// 	this.list_param = {...this.list_param, sort: order_sort};
	// 	// 	uni.setStorageSync('order_sort', '0');
	// 	// }
	// 	this.getData();
	// },
	onPullDownRefresh() {
		console.log('=====上拉刷新refresh');
		this.getData();
		setTimeout(() => {
			uni.stopPullDownRefresh()
		}, 200);
	},
	async onReachBottom() {
		console.log('=====拉到底部onReachBottom');
		if (!this.pullUpOn) return;
		this.loadding = true;
		const token = uni.getStorageSync('token');
		let headers = {"Authorization":"Bearer "+token};
		this.list_param = {...this.list_param,p:++this.nowPage}
		let ret = await http.myOrder(this.$refs.toast, this.list_param, headers);
		var retData = ret.data;
		if(retData.orderList){
			this.orderList = [...this.orderList,...retData.orderList];
			this.nowPage = this.nowPage + 1;
		}else{
			this.loadding = false;
			this.pullUpOn = false;
		}
	},
	methods: {
		async getData(){
			//获取用户登陆信息
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			console.log('list_param:', this.list_param);
			let ret = await http.myOrder(this.$refs.toast, this.list_param, headers);
			var retData = ret.data;
			console.log('myOrder页面,获取到的数据:', retData);
			this.orderNum = retData.orderNum;
			this.orderList = retData.orderList;
			this.loadding = true;
		},
		async tabSelect(e) {
			this.TabCur = e.currentTarget.dataset.id
			//获取用户登陆信息
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			var param = {
				flag: this.TabCur
			}
			let ret = await http.myOrder(this.$refs.toast, param, headers);
			var retData = ret.data;
			console.log('myOrder页面,获取到的数据:', retData);
			this.orderList = retData.orderList;
		},
		doCancel(orderId){ //提交事件
			var that = this;
			uni.showModal({
				title: '提示',
				content: '确认取消订单吗？',
				success: function (res) {
					if (res.confirm) {
						that.doCancelTwo(orderId);
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		},
		async doCancelTwo(orderId){
			//用户登陆信息
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			var param = {
				orderId: orderId
			};
			let ret = await http.orderDoCancel(this.$refs.toast, param, headers);
			var retData = ret.data;
			this.getData();
		},
		openOrderDetail(orderId) {
			uni.navigateTo({
				url: '/pages/order/myOrderDetail?orderId='+orderId
			})
		},
		openEvaluationOperate(orderId) {
			uni.navigateTo({
				url: '/pagesA/evaluation/publish?orderId='+orderId
			})
		},
		openProductList() {
			uni.navigateTo({
				url: '/pages/product/productList'
			})
		},
	}
}
</script>

<style>
</style>
